package service;

import cn.hutool.core.util.StrUtil;
import pojo.Book;
import pojo.Book2;

import java.util.ArrayList;
import java.util.List;

public class ConvertBooksType {
    public List<Book2> parseBooks(List<Book> books){
        List<Book2> book2s = new ArrayList<>();
        for (int i = 0; i < books.size(); i++) {
            Book2 book2 = new Book2(); // 创建一个新的 Book2 对象
            book2.setId(StrUtil.toString(books.get(i).getId()));
            book2.setName(books.get(i).getName());
            book2.setAuthor(books.get(i).getAuthor());
            book2.setPublisher(books.get(i).getPublisher());
            book2.setPrice(books.get(i).getPrice());
            book2.setImageName(books.get(i).getImageName());
            book2.setDescription(books.get(i).getDescription());
            book2s.add(book2); // 将新创建的 Book2 对象添加到 book2s 列表中
        }
        return book2s;
    }
    public Book2 parseBook(Book book){
        /**
         * id,
         *                name,
         *                author,
         *                publisher,
         *                price,
         *                image_name AS imageName,
         *                description
         */
        Book2 book2 = new Book2();
        book2.setId(book.getId().toString());
        book2.setName(book.getName());
        book2.setAuthor(book.getAuthor());
        book2.setPublisher(book.getPublisher());
        book2.setPrice(book.getPrice());
        book2.setImageName(book.getImageName());
        book2.setDescription(book.getDescription());
        return book2;
    }
}
